﻿using System;
using System.Collections.Generic;
using Flagwind.Options;
using Flagwind.Options.Configuration;

namespace Flagwind.Data.Configuration
{
	public class GeneralOption : OptionConfigurationElement
	{
		#region 常量定义

		private const string XML_ENABLELOG_ATTRIBUTE = "enableLog";
		private const string XML_EXECUTETIME_ATTRIBUTE = "executeTime";
		private const string XML_PROVIDERS_COLLECTION = "providers";
		private const string XML_MAPPINGS_COLLECTION = "mappings";

		#endregion

		#region 公共属性

		[OptionConfigurationProperty(XML_ENABLELOG_ATTRIBUTE, DefaultValue = true)]
		public bool EnableLog
		{
			get
			{
				return (bool)this[XML_ENABLELOG_ATTRIBUTE];
			}
			set
			{
				this[XML_ENABLELOG_ATTRIBUTE] = value;
			}
		}

		[OptionConfigurationProperty(XML_EXECUTETIME_ATTRIBUTE, DefaultValue = 0)]
		public int ExecuteTime
		{
			get
			{
				return (int)this[XML_EXECUTETIME_ATTRIBUTE];
			}
			set
			{
				if(value < 0)
				{
					throw new ArgumentOutOfRangeException();
				}
				this[XML_EXECUTETIME_ATTRIBUTE] = value;
			}
		}

		[OptionConfigurationProperty(XML_PROVIDERS_COLLECTION)]
		public ProviderElementCollection Providers
		{
			get
			{
				return (ProviderElementCollection)this[XML_PROVIDERS_COLLECTION];
			}
		}

		[OptionConfigurationProperty(XML_MAPPINGS_COLLECTION)]
		public MappingElementCollection Mappings
		{
			get
			{
				return (MappingElementCollection)this[XML_MAPPINGS_COLLECTION];
			}
		}

		#endregion
	}
}